package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.CarouselReqDTO;
import com.iafme.dto.res.CarouselResDTO;
import com.iafme.mapper.CarouselMapper;
import com.iafme.model.Carousel;
import com.iafme.service.CarouselService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/23 16:39
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements CarouselService {
    @Override
    public Page<CarouselResDTO> lists(CarouselReqDTO carouselReqDTO) {
        Page<Carousel> page=new Page<>(carouselReqDTO.getPageNum(), carouselReqDTO.getPageSize());
        LambdaQueryWrapper<Carousel> wrapper = Wrappers.lambdaQuery(Carousel.class).eq(Carousel::getType,carouselReqDTO.getType()).orderByDesc(Carousel::getCreateTime);
        return Convert.convert(new TypeReference<Page<CarouselResDTO>>() {
        },this.page(page, wrapper));
    }
}
